home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / ZICS.CPP < prev    next >
C/C++ Source or Header  |  1993-08-09  |  10KB  |  352 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    zics.cpp
  5. //   Title:    9 Digit ZIP Disc Interface
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class ZI_CS.
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <zi.hpp>
  41. #define USE_WIN_CS
  42. #if OS_DOS
  43. #include <zid.hpp>
  44. #elif OS_WINDOWS
  45. #include <ziw.hpp>
  46. #else
  47. #include <zio.hpp>
  48. #endif
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //   Description:    Default constructor
  53. //    Parameters:
  54. //       Returns:    
  55. //----------------------------------------------------------------------------
  56. FN_M ZI_CS::ZI_CS(Z4_STATE _state, PCSZ _pcszCity)
  57. : ZN_WINDOW("WIN_CS", ZN_LOAD_CENTER|ZN_LOAD_HELPBAR|ZN_LOAD_NO_SHOW)
  58. {
  59.     ZI_CS::Initialize(CL_INIT_CLASS);
  60.     state = _state;
  61.     pcszCity = _pcszCity;
  62.     Setup();
  63. }
  64.  
  65.  
  66. //----------------------------------------------------------------------------
  67. //   Description:    Destructor
  68. //    Parameters:
  69. //       Returns:    
  70. //----------------------------------------------------------------------------
  71. FN_M ZI_CS::~ZI_CS()
  72. {
  73.     ZI_CS::Destroy(FALSE);
  74.     Terminate();
  75. }
  76.  
  77.  
  78. //----------------------------------------------------------------------------
  79. //   Description:    This function attempts to make a partial match to a state
  80. //                          name and place the virtual list selector on that state.
  81. //    Parameters:
  82. //       Returns:    TRUE if successful.
  83. //----------------------------------------------------------------------------
  84. VOID FN_M ZI_CS::CheckMatch()
  85. {
  86.     if (!fInit)
  87.         return ;
  88.  
  89.     PCSZ pcszCity = GetString(FID(STR_SEARCH));
  90.     PCSZ pcszState = GetString(FID(STR_STATE));
  91.  
  92.     if (pcszCity == NULL || pcszState == NULL)
  93.         return ;
  94.  
  95.     CHAR szWork[160];
  96.     strcpy(szWork, pcszCity);
  97.     strtrim(szWork);
  98.  
  99.     state = Z4_INQ::st_file.Find(pcszState);
  100.  
  101.     if (stricmp(szLastMatch, szWork) == 0
  102.     && stateLast == state)
  103.         return ;
  104.  
  105.     strcpy(szLastMatch, szWork);
  106.     stateLast = state;
  107.  
  108.     if (!Z4_INQ::cs_file.First(Z4_INQ::cs, stateLast, szLastMatch))
  109.         return ;
  110.     do
  111.         {
  112.         if (Z4_INQ::cs.state > state
  113.         || (Z4_INQ::cs.state == state
  114.         && stricmp(Z4_INQ::cs.szCity, szLastMatch) >= 0))
  115.             break;
  116.         }
  117.     while (Z4_INQ::cs_file.Next(Z4_INQ::cs));
  118.     SetVlistPos((LONG)Z4_INQ::cs_file.RecordNo());
  119.     return ;
  120. }
  121.  
  122.  
  123. //----------------------------------------------------------------------------
  124. //   Description:    Destroy object. Free any resources used by object.
  125. //                          Normally called by destructor.
  126. //                        Should allow multiple calls from various classes.
  127. //                        A class should almost always re-init its variables when 
  128. //                        it is destroyed to prevent accidents.
  129. //    Parameters:    fDestroyAll        Destroy parents also?
  130. //                                            Default is TRUE.
  131. //       Returns:    TRUE if successful.
  132. //----------------------------------------------------------------------------
  133. BOOL FN_M ZI_CS::Destroy(BOOL fDestroyAll)
  134. {
  135.     ZI_CS::Initialize(CL_INIT_CLASS_VARS);
  136.     if (fDestroyAll)                            // Destroy parent.
  137.         ZI_CS_PARENT::Destroy(fDestroyAll);
  138.     return TRUE;
  139. }
  140.  
  141.  
  142. //----------------------------------------------------------------------------
  143. //   Description:    Display detail windows
  144. //    Parameters:
  145. //       Returns:    TRUE if successful.
  146. //----------------------------------------------------------------------------
  147. BOOL FN_M ZI_CS::Detail()
  148. {
  149.     if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, lCurrent))
  150.         return FALSE;
  151.     if (lClick != lCurrent)
  152.         SendMessage(ZiMainWindow(), ZI_MSG_CLICK);
  153.  
  154.     lClick = lCurrent;
  155.     PZI_CS_DETAIL pzi_cs_detail = new ZI_CS_DETAIL(Z4_INQ::cs);
  156.     if (pzi_cs_detail == NULL)
  157.         return ErrorNoMem();
  158.     else if (pzi_cs_detail->IsValid())
  159.         pzi_cs_detail->Show();
  160.     return TRUE;
  161. }
  162.  
  163.  
  164. //----------------------------------------------------------------------------
  165. //   Description:    Initialize object. 
  166. //                          Normally called by constructor.
  167. //                        Should allow multiple calls from various classes.
  168. //    Parameters:    sInit        Initialization code. May be one of the following:
  169. //                                        CL_INIT_CLASS            Reset class variables and
  170. //                                                                    and dynamic allocations for
  171. //                                                                    this class only.
  172. //                                        CL_INIT_CLASS_VARS    Reset class variables for
  173. //                                                                    this class only.
  174. //                                        CL_INIT_VARS            Reset class variables for
  175. //                                                                    this class only.
  176. //                                        CL_INIT_ALL                Initialize class and all 
  177. //                                                                    parent class, including
  178. //                                                                    dynamic memory allocation.
  179. //                                    Default is CL_INIT_ALL
  180. //       Returns:    TRUE if successful.
  181. //----------------------------------------------------------------------------
  182. BOOL FN_M ZI_CS::Initialize(SHORT sInit)
  183. {
  184.     if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
  185.         ZI_CS_PARENT::Initialize(sInit);
  186.  
  187.     szLastMatch[0] = '\0';
  188.     lCurrent = 0;
  189.     lRecords = 0;
  190.     stateLast = Z4_ST_INVALID;
  191.     state = Z4_ST_INVALID;
  192.     fInit = FALSE;
  193.     lClick = -1L;
  194.     pcszCity = NULL;
  195.     return TRUE;
  196. }
  197.  
  198.  
  199. //----------------------------------------------------------------------------
  200. //   Description:    
  201. //    Parameters:
  202. //       Returns:    TRUE if successful.
  203. //----------------------------------------------------------------------------
  204. BOOL FN_M ZI_CS::Query(PZN_VLIST_ELEM pzn_vlist_elem)
  205. {
  206.     pzn_vlist_elem->pszBuf = szFormat;
  207.     szFormat[0] = '\0';
  208.     if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, pzn_vlist_elem->lId))
  209.         return FALSE;
  210.  
  211.     sprintf(szFormat, "\t%s\t%s\t%s\t%s%s",
  212.         Z4_ST_FILE::Abbreviation(Z4_INQ::cs.state), Z4_INQ::cs.szCity,
  213.        Z4_INQ::cs.szZip5Lo,
  214.        (Z4_INQ::cs.szZip5Hi[0] ? "- ": ""),
  215.        Z4_INQ::cs.szZip5Hi);
  216.     return TRUE;
  217. }
  218.  
  219.  
  220. //----------------------------------------------------------------------------
  221. //   Description:    
  222. //    Parameters:
  223. //       Returns:    TRUE if successful.
  224. //----------------------------------------------------------------------------
  225. BOOL FN_M ZI_CS::Select()
  226. {
  227.     if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, lCurrent))
  228.         return FALSE;
  229.     PSZ pszZIP = NULL;
  230.     if (!Z4_INQ::cs.szZip5Hi[0])
  231.         {
  232.         if (lClick != lCurrent)
  233.             SendMessage(ZiMainWindow(), ZI_MSG_CLICK);
  234.  
  235.         pszZIP = Z4_INQ::cs.szZip5Lo;
  236.         }
  237.     SendMessage(ZiMainWindow(), ZI_MSG_STATE, NULL, (PVOID)Z4_ST_FILE::Abbreviation(Z4_INQ::cs.state));
  238.     PCSZ pcszCity = (Z4_INQ::cs.facility == Z4_FACILITY_OTHER ? Z4_INQ::cs.szLastLineName: Z4_INQ::cs.szCity);
  239.     SendMessage(ZiMainWindow(), ZI_MSG_CITY, NULL, (PVOID)pcszCity);
  240.     SendMessage(ZiMainWindow(), ZI_MSG_ZIP5, NULL, (PVOID)pszZIP);
  241.     return TRUE;
  242. }
  243.  
  244.  
  245. //----------------------------------------------------------------------------
  246. //   Description:    Event monitor function.
  247. //    Parameters:    msg        Event code
  248. //                        pv1            Data pointer 1
  249. //                        pv2            Data pointer 2
  250. //       Returns:    Event code
  251. //----------------------------------------------------------------------------
  252. ZN_MSG FN_M ZI_CS::User(ZN_MSG msg, PVOID, PVOID pv2)
  253. {
  254.     switch (msg)
  255.         {
  256.         case ZN_MSG_INIT:
  257.             {
  258.             SetMouse(MOUSE_HOURGLASS);
  259.             SetString(FID(STR_STATE), (PCSZ)Z4_ST_FILE::Abbreviation(state));
  260.             if (pcszCity)
  261.                 SetString(FID(STR_SEARCH), pcszCity);
  262.             fInit = TRUE;
  263.             CheckMatch();
  264.             SetMouse();
  265.             SetCurrent(FID(STR_SEARCH));
  266.             }
  267.             return msg;
  268.  
  269.         case ZN_MSG_TERMINATE:
  270.             return msg;
  271.  
  272.         case ZN_MSG_VLIST_INIT:
  273.             {
  274. static int aiTabstops[] = { 2, 6, 55, 62, 0, 0 };
  275.  
  276.             PZN_VLIST_INIT pzn_vlist_init = (PZN_VLIST_INIT)pv2;
  277.             lRecords = (LONG)Z4_INQ::cs_file.Records();
  278.             pzn_vlist_init->lElems = lRecords;
  279.             pzn_vlist_init->fs = ZN_VLIST_SINGLE|ZN_VLIST_TITLE;
  280.             pzn_vlist_init->aiTabstops = aiTabstops;
  281.             }
  282.             return msg;
  283.  
  284.         case ZN_MSG_VLIST_TITLE:
  285.             {
  286.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  287.             pzn_vlist_elem->pszBuf = szFormat;
  288.             strcpy(szFormat, "\tST\tCity\tZIP");
  289.             }
  290.             return msg;
  291.         }
  292.     if (IsError())                                // Error condition
  293.         return msg;
  294.     switch (msg)
  295.         {
  296.         case ZN_MSG_LIST_SELECT:
  297.         case ZN_MSG_LIST_DBL_CLK:
  298.         case ZN_MSG_STRING_CHANGE:
  299.             CheckMatch();
  300.             break;
  301.  
  302.         case ZN_MSG_VLIST_QUERY:
  303.             Query((PZN_VLIST_ELEM)pv2);
  304.             break;
  305.  
  306.         case ZN_MSG_VLIST_SELECT:
  307.             {
  308.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  309.             lCurrent = pzn_vlist_elem->lId;
  310.             }
  311.             // Fall through
  312.         case ZN_MSG_VLIST_CURRENT:
  313.             {
  314.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  315.             LONG lRec = pzn_vlist_elem->lId;
  316.             sprintf(szFormat, "City %ld of %ld", lRec+1, lRecords);
  317.             SetHelp(szFormat);
  318.             }
  319.             break;
  320.  
  321.         case ZN_MSG_VLIST_DBL_CLK:
  322.             {
  323.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  324.             lCurrent = pzn_vlist_elem->lId;
  325.             }
  326.             // Fall through
  327.         case TB_DETAIL:
  328.             Detail();
  329.             break;
  330.  
  331.         case ZN_MSG_HELP:
  332.             return ZN_MSG_NO_HELP;
  333.  
  334.         case TB_CLOSE:
  335.             Close();
  336.             break;
  337.  
  338.         case TB_SELECT:
  339.             Select();
  340.             Close();
  341.             break;
  342.  
  343.         case TB_HELP:
  344.             NotDone();
  345.             break;
  346.         }
  347.     return msg;
  348. }
  349. //----------------------------------------------------------------------------
  350. //------------------------------- End of File --------------------------------
  351. //----------------------------------------------------------------------------
  352.